home *** CD-ROM | disk | FTP | other *** search
/ Aminet 44 / Aminet 44 (2001)(GTI - Schatztruhe)[!][Aug 2001].iso / Aminet / dev / gui / gtlayout.lha / Source / LTP_Draw.c < prev    next >
C/C++ Source or Header  |  1999-01-02  |  8KB  |  392 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1999 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. /*****************************************************************************/
  15.  
  16. #include <graphics/gfxmacros.h>
  17.  
  18. #include <stdarg.h>
  19.  
  20. /*****************************************************************************/
  21.  
  22. #include "Assert.h"
  23.  
  24. /*****************************************************************************/
  25.  
  26.  
  27. VOID
  28. LTP_ResetRenderInfo(struct RastPort *RPort)
  29. {
  30.     SetAfPt(RPort,NULL,0);
  31.     SetDrPt(RPort,0xFFFF);
  32.     SetWrMsk(RPort,0xFF);
  33. }
  34.  
  35.  
  36. /*****************************************************************************/
  37.  
  38.  
  39. VOID
  40. LTP_GhostBox(struct RastPort *RPort,LONG Left,LONG Top,LONG Width,LONG Height,UWORD Pen)
  41. {
  42.     STATIC const UWORD Ghosting[2] = { 0x4444,0x1111 };
  43.  
  44.     LTP_SetPens(RPort,Pen,0,JAM1);
  45.  
  46.     SetAfPt(RPort,(UWORD *)Ghosting,1);
  47.     LTP_FillBox(RPort,Left,Top,Width,Height);
  48.     SetAfPt(RPort,NULL,0);
  49. }
  50.  
  51.  
  52. /*****************************************************************************/
  53.  
  54.  
  55. VOID
  56. LTP_EraseBox(struct RastPort *rp,LONG left,LONG top,LONG width,LONG height)
  57. {
  58.     if(width > 0 && height > 0)
  59.         EraseRect(rp,left,top,left + width - 1,top + height - 1);
  60. }
  61.  
  62.  
  63. /*****************************************************************************/
  64.  
  65.  
  66. VOID
  67. LTP_FillBox(struct RastPort *rp,LONG left,LONG top,LONG width,LONG height)
  68. {
  69.     if(width > 0 && height > 0)
  70.         RectFill(rp,left,top,left + width - 1,top + height - 1);
  71. }
  72.  
  73.  
  74. /*****************************************************************************/
  75.  
  76.  
  77. VOID
  78. LTP_DrawLine(struct RastPort *rp,LONG x0,LONG y0,LONG x1,LONG y1)
  79. {
  80.         /* Recent studies reveal that for horizontal and
  81.          * vertical lines RectFill() is in most cases faster
  82.          * than Move()..Draw(). This only works if we don't
  83.          * rely upon rp->cp_x/cp_y being updated by Draw().
  84.          * As of v26.11 the library no longer does this.
  85.          */
  86.  
  87.     if(x0 == x1 || y0 == y1)
  88.     {
  89.             // If there only were a `C' primitive to swap
  90.             // two variables...
  91.  
  92.         if(x0 > x1)
  93.             x0 ^= x1, x1 ^= x0, x0 ^= x1;
  94.  
  95.         if(y0 > y1)
  96.             y0 ^= y1, y1 ^= y0, y0 ^= y1;
  97.  
  98.         RectFill(rp,x0,y0,x1,y1);
  99.     }
  100.     else
  101.     {
  102.         Move(rp,x0,y0);
  103.         Draw(rp,x1,y1);
  104.     }
  105. }
  106.  
  107. VOID
  108. LTP_PolyDraw(struct RastPort *rp,LONG totalPairs,LONG left,LONG top,...)
  109. {
  110.     LONG x0,y0,x1,y1;
  111.     LONG *pairs;
  112.     va_list args;
  113.  
  114.     x0 = left;
  115.     y0 = top;
  116.  
  117.     va_start(args,top);
  118.  
  119.     pairs = (LONG *)args;
  120.  
  121.     while(--totalPairs > 0)
  122.     {
  123.         x1 = *pairs++;
  124.         y1 = *pairs++;
  125.  
  126.         LTP_DrawLine(rp,x0,y0,x1,y1);
  127.  
  128.         x0 = x1;
  129.         y0 = y1;
  130.     }
  131.  
  132.     va_end(args);
  133. }
  134.  
  135.  
  136. /*****************************************************************************/
  137.  
  138.  
  139. VOID
  140. LTP_RenderBevel(struct RastPort *rp,UWORD *pens,LONG left,LONG top,LONG width,LONG height,BOOL recessed,WORD thickness)
  141. {
  142.     LONG pen1,pen2;
  143.  
  144.     if(recessed)
  145.     {
  146.         pen1 = SHADOWPEN;
  147.         pen2 = SHINEPEN;
  148.     }
  149.     else
  150.     {
  151.         pen1 = SHINEPEN;
  152.         pen2 = SHADOWPEN;
  153.     }
  154.  
  155.     LTP_SetAPen(rp,pens[pen1]);
  156.     LTP_PolyDraw(rp,3,
  157.         left,top + height - 1,
  158.         left,top,
  159.         left + width - 2,top);
  160.  
  161.     if(thickness > 1)
  162.     {
  163.         LTP_DrawLine(rp,left + 1,top + 1,left + 1,top + height - 2);
  164.  
  165.         if(thickness > 2)
  166.         {
  167.             LTP_PolyDraw(rp,3,
  168.                 left + 2,top + height - 3,
  169.                 left + 2,top + 1,
  170.                 left + width - 3,top + 1);
  171.         }
  172.     }
  173.  
  174.     LTP_SetAPen(rp,pens[pen2]);
  175.     LTP_PolyDraw(rp,3,
  176.         left + width - 1,top,
  177.         left + width - 1,top + height - 1,
  178.         left + 1,top + height - 1);
  179.  
  180.     if(thickness > 1)
  181.     {
  182.         LTP_DrawLine(rp,left + width - 2,top + height - 2,left + width - 2,top + 1);
  183.  
  184.         if(thickness > 2)
  185.         {
  186.             LTP_PolyDraw(rp,3,
  187.                 left + width - 3,top + 2,
  188.                 left + width - 3,top + height - 2,
  189.                 left + 2,top + height - 2);
  190.         }
  191.     }
  192. }
  193.  
  194. VOID
  195. LTP_DrawBevel(LayoutHandle *handle,LONG left,LONG top,LONG width,LONG height)
  196. {
  197.     if(handle->BevelImage)
  198.     {
  199.         SetAttrs(handle->BevelImage,
  200.             IA_Width,    width,
  201.             IA_Height,    height,
  202.         TAG_DONE);
  203.  
  204.         DrawImageState(&handle->RPort,handle->BevelImage,left,top,IDS_NORMAL,handle->DrawInfo);
  205.     }
  206.     else
  207.         LTP_RenderBevel(&handle->RPort,handle->DrawInfo->dri_Pens,left,top,width,height,TRUE,2);
  208. }
  209.  
  210. VOID
  211. LTP_DrawBevelBox(LayoutHandle *handle,ObjectNode *node)
  212. {
  213.     LTP_DrawBevel(handle,node->Left,node->Top,node->Width,node->Height);
  214. }
  215.  
  216.  
  217. /*****************************************************************************/
  218.  
  219.  
  220. VOID
  221. LTP_PrintText(struct RastPort *rp,STRPTR text,LONG textLen,LONG x,LONG y)
  222. {
  223.     Move(rp,x,y + rp->TxBaseline);
  224.     Text(rp,text,textLen);
  225. }
  226.  
  227.  
  228. /*****************************************************************************/
  229.  
  230.  
  231. VOID
  232. LTP_DrawGroove(LayoutHandle *handle,LONG left,LONG top,LONG width,LONG height,LONG from,LONG to)
  233. {
  234.     struct RastPort *rp = &handle->RPort;
  235.     LONG x,y;
  236.  
  237.     LTP_SetAPen(rp,handle->ShadowPen);
  238.  
  239.     LTP_PolyDraw(rp,5,
  240.         left + 1,top + 1,
  241.         left + 1,top + height - 2,
  242.         left,top + height - 1,
  243.         left,top,
  244.         from - 2,top);
  245.  
  246.     if(from < to)
  247.     {
  248.         x = to + 1;
  249.         y = top + 1;
  250.     }
  251.     else
  252.     {
  253.         x = from - 1;
  254.         y = top;
  255.     }
  256.  
  257.     LTP_PolyDraw(rp,6,
  258.         x,y,
  259.         to + 1,top,
  260.         left + width - 2,top,
  261.         left + width - 3,top + 1,
  262.         left + width - 3,top + height - 2,
  263.         left + 3,top + height - 2);
  264.  
  265.     LTP_DrawLine(rp,
  266.         left + width - 4,top + 2,
  267.         left + width - 4,top + height - 3);
  268.  
  269.     LTP_SetAPen(rp,handle->ShinePen);
  270.  
  271.     if(from < to)
  272.     {
  273.         x = from - 1;
  274.         y = top;
  275.     }
  276.     else
  277.     {
  278.         x = from + 2;
  279.         y = top + 1;
  280.     }
  281.  
  282.     LTP_PolyDraw(rp,9,
  283.         left + width - 2,top + height - 2,
  284.         left + width - 2,top + 1,
  285.         left + width - 1,top,
  286.         left + width - 1,top + height - 1,
  287.         left + 1,top + height - 1,
  288.         left + 2,top + height - 2,
  289.         left + 2,top + 1,
  290.         from - 1,top + 1,
  291.         x,y);
  292.  
  293.     LTP_DrawLine(rp,
  294.         to + 2,top + 1,
  295.         left + width - 4,top + 1);
  296.  
  297.     LTP_DrawLine(rp,
  298.         left + 3,top + 2,
  299.         left + 3,top + height - 3);
  300. }
  301.  
  302.  
  303. /*****************************************************************************/
  304.  
  305.  
  306. VOID
  307. LTP_DrawGroupLabel(LayoutHandle *handle,ObjectNode *node)
  308. {
  309.     struct RastPort *rp;
  310.     LONG left,top,height;
  311.  
  312.     left = node->Left + (node->Width - node->LabelWidth) / 2;
  313.     rp = &handle->RPort;
  314.  
  315.     if(node->Label)
  316.     {
  317.         LONG glyphHeight = handle->GlyphHeight;
  318.  
  319.         top = node->Top + glyphHeight / 2;
  320.         height = node->Height - (glyphHeight + handle->InterHeight) / 2;
  321.     }
  322.     else
  323.     {
  324.         top = node->Top;
  325.         height = node->Height - handle->InterHeight / 2;
  326.     }
  327.  
  328.     if(handle->UseGroove)
  329.     {
  330.         SetAttrs(handle->GrooveImage,
  331.             IA_Width,    node->Width - handle->GlyphWidth,
  332.             IA_Height,    height,
  333.         TAG_DONE);
  334.  
  335.         DrawImageState(rp,handle->GrooveImage,node->Left + handle->GlyphWidth / 2,top,IDS_NORMAL,handle->DrawInfo);
  336.  
  337.         if(node->Label)
  338.             LTP_EraseBox(rp,left,node->Top,node->LabelWidth,handle->GlyphHeight);
  339.     }
  340.     else
  341.         LTP_DrawGroove(handle,node->Left + handle->GlyphWidth / 2,top,node->Width - handle->GlyphWidth,height,left,left + node->LabelWidth - 1);
  342.  
  343.     if(node->Label)
  344.     {
  345.         LTP_SetPens(rp,handle->DrawInfo->dri_Pens[HIGHLIGHTTEXTPEN],0,JAM1);
  346.         LTP_PrintText(rp,node->Label,strlen(node->Label),left + handle->GlyphWidth,node->Top);
  347.     }
  348. }
  349.  
  350. VOID
  351. LTP_DrawGroupFrame(LayoutHandle *handle,ObjectNode *node)
  352. {
  353.     if(handle->GrooveImage)
  354.     {
  355.         SetAttrs(handle->GrooveImage,
  356.             IA_Width,    node->Width,
  357.             IA_Height,    node->Height + 4,
  358.         TAG_DONE);
  359.  
  360.         DrawImageState(&handle->RPort,handle->GrooveImage,node->Left,node->Top - 4,IDS_NORMAL,handle->DrawInfo);
  361.     }
  362.     else
  363.     {
  364.         struct RastPort *rp;
  365.         LONG left,top,width,height;
  366.  
  367.         rp    = &handle->RPort;
  368.  
  369.         left    = node->Left;
  370.         top        = node->Top - 4;
  371.         width    = node->Width;
  372.         height    = node->Height + 4;
  373.  
  374.         LTP_SetAPen(rp,handle->ShinePen);
  375.  
  376.         LTP_PolyDraw(rp,4,
  377.             left,top + height - 1,
  378.             left,top,
  379.             left + 1,top,
  380.             left + 1,top + height - 2);
  381.  
  382.         LTP_SetAPen(rp,handle->ShadowPen);
  383.  
  384.         LTP_PolyDraw(rp,5,
  385.             left + width - 2,top + height - 2,
  386.             left + width - 2,top,
  387.             left + width - 1,top,
  388.             left + width - 1,top + height - 1,
  389.             left + 1,top + height - 1);
  390.     }
  391. }
  392.